package com.xiaohongshu.kafkademo.service;


import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

@Service
@Slf4j
public class AsyncService {


    @Async(value = "whk-prx")
    public CompletableFuture<String> processDataAsync(String data) {
        try {
            Thread.sleep(2000);
            // 模拟耗时处理
            log.info("开始异步调用: " + Thread.currentThread().getName());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }

        return CompletableFuture.completedFuture("处理完成: " + data);
    }

    @Async(value = "whk-prx")
    public void sendEmailAsync(String email, String message) {
        // 异步发送邮件
        log.info("开始异步调用: " + Thread.currentThread().getName());
        System.out.println("发送邮件到: " + email);
        System.out.println("内容: " + message);
    }
}
